package servlet;

import dao.ArticleDao;
import dao.CollectionDao;
import dao.CommentDao;
import dao.daoimpl.ArticleDaoImpl;
import dao.daoimpl.CollectionDaoImpl;
import dao.daoimpl.CommentDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name="BrowseBlogServlet",urlPatterns = "/BrowseBlogServlet")
public class BrowseBlogServlet extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");/*防止乱码*/
            int articleId=Integer.parseInt(request.getParameter("browseArticleId"));/*博客id*/
            ArticleDao articleDao=new ArticleDaoImpl();
            CommentDao commentDao=new CommentDaoImpl();
            CollectionDao collectionDao=new CollectionDaoImpl();
            try {
                request.getSession().setAttribute("blogArticle",articleDao.getArticle(articleId));/*返回数据*/
                request.getSession().setAttribute("blogComments",commentDao.getComments(articleId));
            } catch (SQLException sqlException) {
                sqlException.printStackTrace();
            }
        }
        protected  void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
            doPost(request,response);
        }
}
